package com.ruoyi.bizsys.service.impl;

import com.ruoyi.bizsys.domain.BankAccount;
import com.ruoyi.bizsys.domain.RealNameAuth;
import com.ruoyi.bizsys.mapper.BankAccountMapper;
import com.ruoyi.bizsys.service.IBankAccountService;
import com.ruoyi.bizsys.vo.BankAccountVo;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * BankAccountService业务层处理
 *
 * @author african-loan
 * @date 2021-12-28
 */
@Service
public class BankAccountServiceImpl implements IBankAccountService {
    @Autowired
    private BankAccountMapper bankAccountMapper;

    /**
     * 查询BankAccount
     *
     * @param id BankAccountID
     * @return BankAccount
     */
    @Override
    public BankAccount selectBankAccountById(Long id) {
        return bankAccountMapper.selectBankAccountById(id);
    }

    /**
     * 查询BankAccount列表
     *
     * @param bankAccount BankAccount
     * @return BankAccount
     */
    @Override
    public List<BankAccount> selectBankAccountList(BankAccount bankAccount) {
        return bankAccountMapper.selectBankAccountList(bankAccount);
    }

    /**
     * 新增BankAccount
     *
     * @param bankAccount BankAccount
     * @return 结果
     */
    @Override
    public int insertBankAccount(BankAccount bankAccount) {
        bankAccount.setCreateTime(DateUtils.getNowDate());
        return bankAccountMapper.insertBankAccount(bankAccount);
    }

    /**
     * 修改BankAccount
     *
     * @param bankAccount BankAccount
     * @return 结果
     */
    @Override
    public int updateBankAccount(BankAccount bankAccount) {
        return bankAccountMapper.updateBankAccount(bankAccount);
    }

    /**
     * 批量删除BankAccount
     *
     * @param ids 需要删除的BankAccountID
     * @return 结果
     */
    @Override
    public int deleteBankAccountByIds(Long[] ids) {
        return bankAccountMapper.deleteBankAccountByIds(ids);
    }

    /**
     * 删除BankAccount信息
     *
     * @param id BankAccountID
     * @return 结果
     */
    @Override
    public int deleteBankAccountById(Long id) {
        return bankAccountMapper.deleteBankAccountById(id);
    }

    @Override
    public int updateBankAccountIsDefault(BankAccount bankAccount) {
        return bankAccountMapper.updateBankAccountIsDefault(bankAccount);
    }

    @Override
    public List<BankAccountVo> selectBankAccountAndNameList(BankAccount bankAccount) {
        return bankAccountMapper.selectBankAccountAndNameList(bankAccount);
    }

    @Override
    public int countByCustNo(String userId) {
        return bankAccountMapper.countByCustNo(userId);
    }

    @Override
    public int saveByRealNameAuth(RealNameAuth realNameAuth) {
        BankAccount bankAccount = new BankAccount();
        bankAccount.setUserId(realNameAuth.getUserId());
        bankAccount.setCustNo(realNameAuth.getCustNo());
        bankAccount.setBankCode(realNameAuth.getBankCode());
        bankAccount.setAccountNumber(realNameAuth.getAccountNumber());
        bankAccount.setIsDefault("1");
        return this.insertBankAccount(bankAccount);
    }

    @Override
    public int selectBankAccountCnt(String custNo) {
        int i = bankAccountMapper.selectBankAccountCnt(custNo);
        if (i == 0) {
            return -1;
        }
        return i;
    }

    @Override
    public String selectBankAccountMaxCnt(String custNo) {
        return bankAccountMapper.selectBankAccountmaxCnt(custNo);
    }
}
